home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / pdcsrc.lzh / A68k / A68kglb.h < prev    next >
C/C++ Source or Header  |  1990-04-19  |  12KB  |  269 lines

  1. /*------------------------------------------------------------------*/
  2. /*                                    */
  3. /*            MC68000 Cross Assembler                */
  4. /*                                    */
  5. /*        Copyright (c) 1985 by Brian R. Anderson            */
  6. /*                                    */
  7. /*                Global variables - November 2, 1989            */
  8. /*                                    */
  9. /*   This program may be copied for personal, non-commercial use    */
  10. /*   only, provided that the above copyright notice is included        */
  11. /*   on all copies of the source code.  Copying for any other use   */
  12. /*   without the consent of the author is prohibited.            */
  13. /*                                    */
  14. /*------------------------------------------------------------------*/
  15. /*                                    */
  16. /*        Originally published (in Modula-2) in            */
  17. /*        Dr. Dobb's Journal, April, May, and June 1986.        */
  18. /*                                    */
  19. /*     AmigaDOS conversion copyright 1989 by Charlie Gibbs.        */
  20. /*                                    */
  21. /*------------------------------------------------------------------*/
  22.  
  23. #ifdef PRIMARY
  24. #define GLOBAL
  25. #else
  26. #define GLOBAL extern
  27. #endif
  28.  
  29. GLOBAL char SourceFN[MAXFN];    /* Source file name */
  30. GLOBAL char HeaderFN[MAXFN];    /* Header file name (-h) */
  31. GLOBAL char SrecFN[MAXFN];    /* Object file name (-o) */
  32. GLOBAL char InclList[MAXLINE];    /* List of directories to search (-i) */
  33. GLOBAL char IdntName[MAXLINE];    /* Program unit name */
  34.  
  35. struct fs {
  36.     int  fd;        /* File handle */
  37.     char *Buf;        /* Pointer to buffer */
  38.     char *Ptr;        /* Current position in buffer */
  39.     char *Lim;        /* Logical end of buffer */
  40. };
  41. GLOBAL struct fs In;    /* Input file */
  42. GLOBAL struct fs Eq;    /* Equate file */
  43. GLOBAL struct fs List;    /* Listing file */
  44. GLOBAL struct fs Srec;    /* Object file */
  45.  
  46. /*    Command-line options    */
  47.  
  48. GLOBAL int DumpSym;    /* -d Dump the symbol table. */
  49. GLOBAL char DumpSymList[MAXLINE];    /* -d selection list */
  50. GLOBAL int FwdProc;    /* -f Special processing for forward references */
  51. GLOBAL int KeepTabs;    /* -k Keep tabs in the listing file. */
  52. GLOBAL int SuppList;    /* (neither -l nor -x) Suppress listing file. */
  53. GLOBAL int NoOpt;    /* -n Suppress all optimization. */
  54. GLOBAL int LnMax;    /* -p Maximum number of lines per page */
  55. GLOBAL int Quiet;    /* -q Line no. display interval (0 to suppress) */
  56. GLOBAL long HashSize;    /* -w Number of entries in the hash table */
  57. GLOBAL int XrefList;    /* -x Produce a cross-reference listing. */
  58. GLOBAL int HashStats;    /* -y Display hashing statistics. */
  59. GLOBAL int DebugStart;    /* -z Debug display starts here. */
  60. GLOBAL int DebugEnd;    /* -z Debug display ends here. */
  61.  
  62. GLOBAL char TTLstring[MAXLINE];    /* Title string */
  63.  
  64. GLOBAL int  LabLine;        /* Last labeled line number */
  65. GLOBAL int  LineCount;        /* Source line counter */
  66. GLOBAL char Line[MAXLINE];    /* Current source line */
  67. GLOBAL char Label[MAXLINE];    /* Instruction label */
  68. GLOBAL char OpCode[MAXLINE];    /* Instruction mnemonic */
  69. GLOBAL char SrcOp[MAXLINE];    /* First (source) operand */
  70. GLOBAL char DestOp[MAXLINE];    /* Second (destination) operand */
  71. GLOBAL int  LabLoc, OpLoc;    /* Label and mnemonic start here */
  72. GLOBAL int  SrcLoc, DestLoc;    /* Operands start here. */
  73. GLOBAL int  Dir, PrevDir;    /* Assembler directive */
  74. GLOBAL int  NumSyms;        /* Number of symbols */
  75. GLOBAL long ObjOp;        /* OpCode object code */
  76. GLOBAL long ObjSrc;        /* Source operand object code */
  77. GLOBAL long ObjDest;        /* Destination operand object code */
  78. GLOBAL char ObjString[MAXLINE];    /* String data */
  79. GLOBAL int  nO, nS, nD, nX;    /* Length of above components */
  80. GLOBAL int  PrntAddr;        /* Print AddrCnt on listing. */
  81. GLOBAL int  MakeHunk;        /* We must make a hunk. */
  82. GLOBAL int  ListOff;        /* NOLIST is supressing listing lines. */
  83. GLOBAL int  LnCnt;        /* Number of lines on current page */
  84. GLOBAL int  PgCnt;        /* Page number */
  85. GLOBAL long Hunk2;        /* Hunk number (from GetValue) */
  86. GLOBAL int  DefLine2;        /* Definition line number */
  87. GLOBAL int  SingleFlag;        /* Expression consists of a single term. */
  88. GLOBAL int  GotEqur;        /* We have register equates. */
  89. GLOBAL int  SmallData;        /* Register for small data model (or -1) */
  90. GLOBAL int  AnyNear;        /* We got at least one NEAR directive. */
  91. GLOBAL int  FwdShort;        /* Forward reference could be made short. */
  92.  
  93. GLOBAL int  Pass2;    /* Pass 2 flag */
  94. GLOBAL long AddrCnt;    /* Location counter */
  95. GLOBAL long AddrAdv;    /* Bump AddrCnt by this much. */
  96. GLOBAL long DupFact;    /* Duplication factor for DCB, 1 otherwise */
  97. GLOBAL long OrgHigh;    /* Highest address reached if we ORG backwards */
  98. GLOBAL long OrgSeek;    /* Return here in Srec if we ORG backwards. */
  99. GLOBAL long EndAddr;    /* END statement transfer address */
  100. GLOBAL long SectStart;    /* Current section (or portion) starts here. */
  101. GLOBAL int  SectLine;    /* Line number where section started */
  102. GLOBAL int  HunkSeq;    /* Hunk sequence number */
  103. GLOBAL long HunkType;    /* Current hunk type */
  104. GLOBAL long HunkFlags;    /* Hunk flags (MEMF_FAST or MEMF_CHIP) */
  105. GLOBAL long CurrHunk;    /* Current hunk number */
  106. GLOBAL long NextHunk;    /* Next available hunk number */
  107. GLOBAL long LenPos;    /* Seek position of current hunk length */
  108. GLOBAL char *LenPtr;    /* Pointer to length if in buffer, else NULL */
  109. GLOBAL int  InclErrs;    /* Error processing INCLUDE statement(s) */
  110. GLOBAL int  InnrFMac;    /* An inner file has been read by a user macro. */
  111. GLOBAL int  OrgFlag;    /* ORG may require object file fixup. */
  112.  
  113. GLOBAL int  SFormat;    /* Generate S-record format. */
  114. GLOBAL long StartAddr;    /* Address that record starts on */
  115. GLOBAL long TempAddr;    /* Address of where we are now */
  116.  
  117. GLOBAL int  IncStart;    /* Start line number of skippable INCLUDE */
  118. GLOBAL struct InFCtl *IncPtr;    /* Copy of InF for skippable INCLUDE */
  119. struct SkipEnt {        /* Skippable INCLUDE description */
  120.     struct SetFixup *Set1;    /*  Pointer to first SET fixup */
  121.     int Start;            /*  Starting line number of INCLUDE */
  122.     int Finish;            /*  Ending line number of INCLUDE */
  123.     int MCount;            /*  Value of MacCount at end of INCLUDE */
  124. };
  125. struct SetFixup {        /* SET symbol fixup entry */
  126.     struct SymTab *Sym;        /* Pointer to symbol table entry */
  127.     long Val;            /* Fixup value */
  128.     long Hunk;            /* Fixup hunk number */
  129. };
  130. GLOBAL struct SkipEnt *SkipLim;    /* Logical end of skippable INCLUDEs */
  131. GLOBAL struct SkipEnt *SkipIdx;    /* Current skippable INCLUDE entry */
  132. GLOBAL struct SetFixup *SetFixLim;    /* Next available SetFixup */
  133.  
  134. struct SymTab {                /* Symbol table */
  135.     struct SymTab *Link;    /* Link to next entry in hash chain */
  136.     char *Nam;    /* Pointer to symbol */
  137.     long Val;    /* Value */
  138.     long Hunk;    /* Hunk number (ORed with MEMF_CHIP or MEM_FAST
  139.             if applicable SECTION
  140.            ~(pointer to symbol) if XREF
  141.            Pointer to macro text if MACRO        */
  142.     int  Defn;    /* Line number where defined */
  143.     int  Flags;    /* Flags bits:    0 - XREF
  144.                 1 - XDEF
  145.                 2 - SET
  146.                 3 - MACRO (symbol is preceded by blank)
  147.                 4 - SECTION (name preceded by 2 blanks
  148.                     and 4-digit hex sequence number)
  149.                 5 - register name (EQUR)
  150.                 6 - register list (REG)
  151.                 7 - PUBLIC (XREF or XDEF will be set) */
  152.     struct Ref *Ref1;    /* Pointer to first reference entry */
  153. };
  154. GLOBAL struct SymTab *SymStart;    /* The symbol table starts here. */
  155. GLOBAL struct SymTab *SymLim;    /* The symbol table ends here. */
  156. GLOBAL struct SymTab *SymCurr;    /* Start of current chunk of data */
  157. GLOBAL struct SymTab *Sym;    /* ReadSymTab sets this up. */
  158. GLOBAL struct SymTab *Sect;    /* Current section's entry */
  159. GLOBAL struct SymTab *SymChunk;    /* Current symbol chunk for NextSym */
  160. GLOBAL struct SymTab *SymChLim;    /* End of *SymChunk chunk */
  161. GLOBAL struct SymTab **Hash;    /* Pointer to hash table */
  162. GLOBAL struct SymTab **SymSort;    /* Symbol sort area */
  163. GLOBAL int  *HashCount;        /* Hashing summary table */
  164.  
  165. struct NameChunk {        /* Chunk of labels or macro text */
  166.     struct NameChunk *Link;    /* Link to the next chunk */
  167.     char *Data[CHUNKSIZE-sizeof(struct NameChunk *)];    /* Data area */
  168. };
  169. GLOBAL struct NameChunk *NameStart;    /* Start of first name chunk */
  170. GLOBAL char             *NameLim;    /* Next available name entry */
  171. GLOBAL struct NameChunk *NameCurr;    /* Start of current name chunk */
  172.  
  173. struct Ref {            /* Reference entry */
  174.     struct Ref *NextRef;    /* Pointer to next reference entry */
  175.     int RefNum[MAXREF];        /* Reference line numbers */
  176. };
  177. GLOBAL struct Ref *RefLim;    /* Next available reference entry */
  178.  
  179. struct RelTab {            /* Relocation table entry */
  180.     struct RelTab *Link;    /* Link to the next entry */
  181.     long Offset;        /* Offset to relocatable value */
  182.     long Hunk;            /* Hunk type to relocate relative to */
  183.     int  Size;            /* Size of relocatable value */
  184. };
  185. GLOBAL struct RelTab *RelStart;    /* Relocation data starts here */
  186. GLOBAL struct RelTab *RelLim;    /* Relocation data ends here */
  187. GLOBAL struct RelTab *RelCurr;    /* Start of current chunk of data */
  188. GLOBAL struct RelTab *RelLast;    /* Last relocation entry added */
  189.  
  190. struct TermStack {        /* Parser's term stack */
  191.     long value;        /* Value */
  192.     long hunk;        /* Hunk number */
  193.     int  oploc;        /* Location in source statement */
  194.     int  defline;    /* Line number where defined */
  195. };
  196. GLOBAL struct TermStack *Term;    /* Term stack pointer */
  197.  
  198. struct OpStack {        /* Parser's operator stack */
  199.     char chr;        /* Operator character */
  200.     int  prec;        /* Precedence */
  201. };
  202. GLOBAL struct OpStack *Ops;    /* Operator stack pointer */
  203.  
  204. GLOBAL char OpPrec[256];    /* Operator precedence look-up table */
  205.  
  206. GLOBAL int  InFNum;        /* Current input nesting level */
  207. struct InFCtl {
  208.     long Pos;            /* Current position in input */
  209.     char *UPtr;            /* Current position in user macro or 0 */
  210.     char *NPtr;            /* File name stack pointer */
  211.     int  Line;            /* Current line number in this file */
  212.     int  NArg;            /* Number of macro arguments or -1 */
  213.     int  MCnt;            /* Macro expansion number (for \@) */
  214. };
  215. GLOBAL struct InFCtl *InF;    /* Macro/include file stack pointer */
  216. GLOBAL struct InFCtl *LowInF;    /* "Low-water mark" for InF */
  217. GLOBAL char *Heap2;        /* Secondary heap */
  218. GLOBAL char *NextFNS;        /* Next input file path/name */
  219. GLOBAL char *High2;        /* Secondary high-water mark */
  220. GLOBAL char *Low2;        /* Low limit from top of heap */
  221.  
  222. GLOBAL int  OuterMac;        /* Level number of outermost macro */
  223. GLOBAL int  MacCount;        /* Number of macros expanded */
  224. GLOBAL int  SkipNest;        /* Skipped IF/ENDC nesting count */
  225. GLOBAL char MacSize[2];        /* Macro call size ("B", "W", or "L") */
  226.  
  227. struct OpConfig {        /* Operand configuration */
  228.     long Value;    /* Value */
  229.     long Hunk;    /* Hunk number */
  230.     int  Defn;    /* Line number where defined */
  231.     int  Mode;    /* Addressing mode */
  232.     int  Loc;    /* Location of operand on Line */
  233.     int  Rn;    /* Register number */
  234.     int  Xn;    /* Index register number */
  235.     int  Xsize;    /* Size of index */
  236.     int  X;    /* Is index Data or Address reg? */
  237.     int  Single; /* The operand is a single term. */
  238. };
  239. GLOBAL struct OpConfig Src, Dest;    /* Source and destination operands */
  240.  
  241. GLOBAL int Size;    /* Size for OpCode */
  242. GLOBAL int InstSize;    /* Size of instruction, including operands */
  243. GLOBAL int AdrModeA;    /* Addressing modes for this instruction */
  244. GLOBAL int AdrModeB;    /*                 ditto                 */
  245. GLOBAL int Op;        /* Raw bit pattern for OpCode */
  246.  
  247. GLOBAL struct FwdBr {    /* Forward branch optimization candidates */
  248.     long Loc;        /* Location of Bcc instruction */
  249.     struct SymTab *FwdSym;    /* Pointer to target label entry */
  250.     int  Line;        /* Line number (copied to FwdTable if OK) */
  251. } FwdBranch[64];
  252. GLOBAL struct FwdBr *FwdLim1;    /* Logical end of FwdBranch */
  253. GLOBAL struct SymTab *FwdBranchFix[128]; /* Symbol table entries to fix */
  254. GLOBAL struct SymTab **FwdFixLimit;    /* Logical end of fixup table */
  255.  
  256. struct FwdTable {
  257.     struct FwdTable *Link;
  258.     int FwdLine[(FWDSIZE-sizeof(struct FwdTable *)) / sizeof (int)];
  259. };
  260. GLOBAL struct FwdTable *FwdStart;    /* Start of first chunk */
  261. GLOBAL int             *FwdLim2;    /* Next available entry */
  262. GLOBAL struct FwdTable *FwdCurr;    /* Start of current chunk */
  263. GLOBAL int             *FwdPtr;        /* Current position in pass 2 */
  264.  
  265. GLOBAL int ErrorCount;
  266.  
  267. /* Error message tables */
  268. GLOBAL int ErrLim, ErrCode[ERRMAX], ErrPos[ERRMAX];
  269.